home *** CD-ROM | disk | FTP | other *** search
/ Digitalfoto 118 / Digitalfoto 118.iso / mac / programas / 00 / 9430830 / swfobject.js < prev    next >
Text File  |  2007-06-13  |  9KB  |  217 lines

  1. /**
  2.  * SWFObject v2.0: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
  3.  *
  4.  * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
  5.  * http://www.opensource.org/licenses/mit-license.php
  6.  *
  7.  */
  8. if(typeof deconcept == "undefined") var deconcept = new Object();
  9. if(typeof deconcept.util == "undefined") deconcept.util = new Object();
  10. if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
  11. deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
  12.     if (!document.getElementById) { return; }
  13.     this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
  14.     this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
  15.     this.params = new Object();
  16.     this.variables = new Object();
  17.     this.attributes = new Array();
  18.     if(swf) { this.setAttribute('swf', swf); }
  19.     if(id) { this.setAttribute('id', id); }
  20.     if(w) { this.setAttribute('width', w); }
  21.     if(h) { this.setAttribute('height', h); }
  22.     if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
  23.     this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
  24.     if (!window.opera && document.all && this.installedVer.major > 7) {
  25.         // only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
  26.         deconcept.SWFObject.doPrepUnload = true;
  27.     }
  28.     if(c) { this.addParam('bgcolor', c); }
  29.     var q = quality ? quality : 'high';
  30.     this.addParam('quality', q);
  31.     this.setAttribute('useExpressInstall', false);
  32.     this.setAttribute('doExpressInstall', false);
  33.     var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
  34.     this.setAttribute('xiRedirectUrl', xir);
  35.     this.setAttribute('redirectUrl', '');
  36.     if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
  37. }
  38. deconcept.SWFObject.prototype = {
  39.     useExpressInstall: function(path) {
  40.         this.xiSWFPath = !path ? "expressinstall.swf" : path;
  41.         this.setAttribute('useExpressInstall', true);
  42.     },
  43.     setAttribute: function(name, value){
  44.         this.attributes[name] = value;
  45.     },
  46.     getAttribute: function(name){
  47.         return this.attributes[name];
  48.     },
  49.     addParam: function(name, value){
  50.         this.params[name] = value;
  51.     },
  52.     getParams: function(){
  53.         return this.params;
  54.     },
  55.     addVariable: function(name, value){
  56.         this.variables[name] = value;
  57.     },
  58.     getVariable: function(name){
  59.         return this.variables[name];
  60.     },
  61.     getVariables: function(){
  62.         return this.variables;
  63.     },
  64.     getVariablePairs: function(){
  65.         var variablePairs = new Array();
  66.         var key;
  67.         var variables = this.getVariables();
  68.         for(key in variables){
  69.             variablePairs.push(key +"="+ variables[key]);
  70.         }
  71.         return variablePairs;
  72.     },
  73.     getSWFHTML: function() {
  74.         var swfNode = "";
  75.         if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
  76.             if (this.getAttribute("doExpressInstall")) {
  77.                 this.addVariable("MMplayerType", "PlugIn");
  78.                 this.setAttribute('swf', this.xiSWFPath);
  79.             }
  80.             swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
  81.             swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
  82.             var params = this.getParams();
  83.              for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
  84.             var pairs = this.getVariablePairs().join("&");
  85.              if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
  86.             swfNode += '/>';
  87.         } else { // PC IE
  88.             if (this.getAttribute("doExpressInstall")) {
  89.                 this.addVariable("MMplayerType", "ActiveX");
  90.                 this.setAttribute('swf', this.xiSWFPath);
  91.             }
  92.             swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
  93.             swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
  94.             var params = this.getParams();
  95.             for(var key in params) {
  96.              swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
  97.             }
  98.             var pairs = this.getVariablePairs().join("&");
  99.             if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
  100.             swfNode += "</object>";
  101.         }
  102.         return swfNode;
  103.     },
  104.     write: function(elementId){
  105.         if(this.getAttribute('useExpressInstall')) {
  106.             // check to see if we need to do an express install
  107.             var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
  108.             if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
  109.                 this.setAttribute('doExpressInstall', true);
  110.                 this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
  111.                 document.title = document.title.slice(0, 47) + " - Flash Player Installation";
  112.                 this.addVariable("MMdoctitle", document.title);
  113.             }
  114.         }
  115.         if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
  116.             var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
  117.             n.innerHTML = this.getSWFHTML();
  118.             return true;
  119.         }else{
  120.             if(this.getAttribute('redirectUrl') != "") {
  121.                 document.location.replace(this.getAttribute('redirectUrl'));
  122.             }
  123.         }
  124.         return false;
  125.     }
  126. }
  127.  
  128. /* ---- detection functions ---- */
  129. deconcept.SWFObjectUtil.getPlayerVersion = function(){
  130.     var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
  131.     if(navigator.plugins && navigator.mimeTypes.length){
  132.         var x = navigator.plugins["Shockwave Flash"];
  133.         if(x && x.description) {
  134.             PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
  135.         }
  136.     }else{
  137.         // do minor version lookup in IE, but avoid fp6 crashing issues
  138.         // see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
  139.         try{
  140.             var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
  141.         }catch(e){
  142.             try {
  143.                 var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
  144.                 PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
  145.                 axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
  146.             } catch(e) {
  147.                 if (PlayerVersion.major == 6) {
  148.                     return PlayerVersion;
  149.                 }
  150.             }
  151.             try {
  152.                 axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
  153.             } catch(e) {}
  154.         }
  155.         if (axo != null) {
  156.             PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
  157.         }
  158.     }
  159.     return PlayerVersion;
  160. }
  161. deconcept.PlayerVersion = function(arrVersion){
  162.     this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
  163.     this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
  164.     this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
  165. }
  166. deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
  167.     if(this.major < fv.major) return false;
  168.     if(this.major > fv.major) return true;
  169.     if(this.minor < fv.minor) return false;
  170.     if(this.minor > fv.minor) return true;
  171.     if(this.rev < fv.rev) return false;
  172.     return true;
  173. }
  174. /* ---- get value of query string param ---- */
  175. deconcept.util = {
  176.     getRequestParameter: function(param) {
  177.         var q = document.location.search || document.location.hash;
  178.         if(q) {
  179.             var pairs = q.substring(1).split("&");
  180.             for (var i=0; i < pairs.length; i++) {
  181.                 if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
  182.                     return pairs[i].substring((pairs[i].indexOf("=")+1));
  183.                 }
  184.             }
  185.         }
  186.         return "";
  187.     }
  188. }
  189. /* fix for video streaming bug */
  190. deconcept.SWFObjectUtil.cleanupSWFs = function() {
  191.     var objects = document.getElementsByTagName("OBJECT");
  192.     for (var i=0; i < objects.length; i++) {
  193.         objects[i].style.display = 'none';
  194.         for (var x in objects[i]) {
  195.             if (typeof objects[i][x] == 'function') {
  196.                 objects[i][x] = function(){};
  197.             }
  198.         }
  199.     }
  200. }
  201. // fixes bug in fp9 see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
  202. if (deconcept.SWFObject.doPrepUnload) {
  203.     deconcept.SWFObjectUtil.prepUnload = function() {
  204.         __flash_unloadHandler = function(){};
  205.         __flash_savedUnloadHandler = function(){};
  206.         window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
  207.     }
  208.     window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
  209. }
  210. /* add Array.push if needed (ie5) */
  211. if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
  212.  
  213. /* add some aliases for ease of use/backwards compatibility */
  214. var getQueryParamValue = deconcept.util.getRequestParameter;
  215. var FlashObject = deconcept.SWFObject; // for legacy support
  216. var SWFObject = deconcept.SWFObject;
  217.